package main

import (
	"fmt"
	"sync"
	"time"
)

// 测试chan同步多个routine的执行
var ss = make(chan int)

func hello() {
	time.Sleep(2 * time.Second)
	ss <- 23
	fmt.Println("hello")
}
func hello2() {
	go hello()
	<-ss
	fmt.Println("world")
}

func waitGroupTask(wait *sync.WaitGroup) {
	fmt.Println("11")
	wait.Done()
}
func testWaitGroupTask() {

}
func main2() {

	local := NewLocal()
	go func() {
		local.Add("xxx", "第一个携程")
		time.Sleep(1 * time.Second)
		fmt.Println(local.Get("xxx"))
	}()
	go func() {
		local.Add("xxx", "第二个携程")
		fmt.Println(local.Get("xxx"))
	}()
	//测试chan的同步
	//hello2()
	group := sync.WaitGroup{}
	for i := 0; i < 100; i++ {
		group.Add(1)
		go waitGroupTask(&group)
	}
	time.Sleep(5 * time.Second)

	group.Wait()
}
